package org.acghub.common.reload;

import lombok.Getter;

import java.util.List;

public interface Reloader<A extends Reloader.Args, R extends Reloader.Result>
{

    int CODE_SUCCESS = 0;
    int CODE_FAILED = -1;

    R reload(A args);

    record Args(String dir, List<String> classNames) {
    }

    @Getter
    class Result
    {

        private int code = CODE_SUCCESS;

        // String or Throwable
        private Object reason;

        public void fail(int code, Object reason)
        {
            this.code = code;
            this.reason = reason;
        }

        public void fail(Object reason)
        {
            this.code = CODE_FAILED;
            this.reason = reason;
        }

        public boolean isSuccess()
        {
            return code == CODE_SUCCESS;
        }

    }
}
